<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
require_once '../classes/ClasseDataManager.php';
require_once '../classes/ConnectionDB.php';

$db = ConnectionDB::getInstance()->connectToDB();
$listaClassi = ClasseDataManager::getInstance()->getClassi($db);
?>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Ricerca studenti</title>
    <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
    <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
    <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
    <style type="text/css">
      @import url("../css/style.css");


      table{
        width: 100%;

      }

      td{
        text-align: center;
      }

      #searchForm {
        padding-top: 3%;
        margin-left: -5px;
      }

     

    </style>
    <script type="text/javascript">
      path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
      var listaStudenti;
      var numItem=10;
      var currentIndex=0;

      window.onload = function(){
        var searchForm = new GlassBox();
        searchForm.init( 'searchForm', '640px', '190px', 'hidden','',true, false);
        searchForm.ipos();
        searchForm.appear();

        var results = new GlassBox();
        results.init( 'results', '1040px', '590px', '','',true,false);
        results.ipos();
        results.appear();
      }

      function xXMLHttpRequest()
      {

        var client = null;
        if (window.XMLHttpRequest)
        {
          client=new XMLHttpRequest();
        }
        // code for IE
        else if (window.ActiveXObject)
        {
          client=new ActiveXObject("Microsoft.XMLHTTP");
        }

        return client;
      }

      function handler()
      {
        if(this.readyState == 4 && this.status == 200)
        {
          //          alert("resp : " + this.responseText);
          var resp = eval(this.responseText);
          listaStudenti = new Array();
          for(i=0;i<resp.length; i++)
          {
            listaStudenti[i] = resp[i];
          }

          manageNavi(0);


        }
        else if (this.readyState == 4 && this.status != 200)
        {
          // fetched the wrong page or network error...
          alert("error this.status : " + this.status );

        }
      }

      function find()
      {
        var client = xXMLHttpRequest();
        client.onreadystatechange = handler;
        var nome = document.getElementById('nome').value;
        var cognome = document.getElementById('cognome').value;
        var classe =document.getElementById('classe').value;

        var param = "nome="+ nome +
          "&cognome="+cognome+
          "&classe="+classe;
        client.open("POST", "searchStudentsListenerJson.php", true);
        client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

        client.send(param);

      }

      function manageNavi(ind)
      {
        var tmp= new Array();

        var str="<table border='1'  cellpadding='5'>"
          +"<tr>"
          +"<th>Codice Studente</th>"
          +"<th>Nome</th>"
          +"<th>Cognome</th>"
          +"<th>Data creazione</th>"
          +"<th>Email</th>"
          +"<th>Classe</th>"
          +"<th>Sezione</th>"
          +"<th>Indirizzo</th>"
          +"<th>Info test</th>"
          +"</tr>";
        var indCurrenct=0;
        while(indCurrenct<numItem)
        {
          //                    alert("idn " + ind);
          if(ind<listaStudenti.length)
          {
            tmp=listaStudenti[ind];
            str+="<tr><td>"+tmp.codiceStudente+"</td>"+
              "<td>"+tmp.nome+"</td>"+
              "<td>"+tmp.cognome+"</td>"+
              "<td>"+tmp.dataCreazione+"</td>";
            if(tmp.email=="")
              str += "<td>&nbsp;</td>";
            else
              str += "<td>"+tmp.email+"</td>";

            str += "<td>"+tmp.ordClasse+"</td>"+
              "<td>"+tmp.sezione+"</td>"+
              "<td>"+tmp.descrizioneIndirizzo+"</td>"+
              "<td><img src='../images/icons/PNG/Magnifying Glass.png' height='30' width='30' title='Risultati' border='0' onclick='javascript:location.href=\"reportLiveTestByStudent.php?codiceStudente="+ tmp[0]+"\"' /></td></tr>";

          }
          ind++;
          indCurrenct++;
        }
        str +="</table>";
        var numTotItem = listaStudenti.length;
        var numPag = Math.ceil(numTotItem / numItem);
        if(numPag > 1)
        {
          str +="<div id='navigator'><center>";
          var current = 0;
          var toPrint=1
          for(k=1;k<=numPag;k++)
          {
            str+="<a href='javascript:manageNavi("+current+")'>"+toPrint+"</a>&nbsp;&nbsp;";
            current= k * numItem;
            toPrint = toPrint+1;
          }
          str+="</center></div>";
        }
        document.getElementById('resultsCont').innerHTML=str;
      }
    </script>
  </head>
  <body>
    <?php include '../portal/header.php'; ?>
    <center>
      <div id="searchForm">
        <table>
          <tr>
            <th>Ricerca studente</th>
          </tr>
          <tr>
            <td>Nome:</td>
            <td><input type="text" name="nome" id="nome" /></td>
          </tr>
          <tr>
            <td>Cognome:</td>
            <td><input type="text" name="cognome" id="cognome" /></td>
          </tr>
          <tr>
            <td>Classe:</td>
            <td>
              <select name="classe" id="classe">
                <option value="">Tutte le classi</option>

                <?
                for ($j = 0; $j < count($listaClassi); $j++) {
                ?>
                  <option value="<?= $listaClassi[$j]->getCodice() ?>">
<?= $listaClassi[$j]->getClasse() ?>
                  <?= $listaClassi[$j]->getSezione() ?>
                  <?= $listaClassi[$j]->getDescrizioneIndirizzo() ?>
                </option>

<? } ?>

              </select>
            </td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
            <td>
              <input type="button" value="Cerca" onclick="find();" />
            </td>
          </tr>


        </table>

      </div>
      <div id="results"><div id="resultsCont"></div></div>
    </center>
  </body>
</html>
